#ifndef INTERNETCLASS_H
#define INTERNETCLASS_H

#include <QObject>
#include <QtNetwork/QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QDebug>
#ifdef _DEBUG
#include <QDebug>
#include <QFile>
#endif

class InternetClass : public QObject
{
    Q_OBJECT
public:
    explicit InternetClass(QObject *parent = 0);
    Q_INVOKABLE void Consultar(const QString &rastreio);
    Q_INVOKABLE void CancelarConsulta();

private:
    QNetworkAccessManager _net;
    QNetworkReply *_rep;
    static const QString _urlConsulta, _postData;
    QList<QString> _cacheRastreios;
    bool _modoBat;

    const QString MontarPostRastreio(const QString &rastreio);
    void EfetivarConsulta(const QString &rastreio);
    void ConsultarBat();
    
signals:    
    void pesquisaIniciada();
    void pesquisaConcluida();
    void consultaCancelada();
    void semResposta();
    void resposta(const QString &dados);

private slots:
    void fimDaConsulta(QNetworkReply *reply);

public slots:
    void consultarSlot(const QString &rastreio);
    
};

#endif // INTERNETCLASS_H
